package com.ywb.ex09.view;

import com.ywb.ex09.tools.MyTools;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 宠物管理窗口类——抽象类
 */
public abstract class PetAdminDialog extends JDialog {
    private   JLabel tableLabel=new JLabel("宠物列表");
    private   JScrollPane  tablePane=new JScrollPane();
    protected  JTable   petTable=new JTable();
    private JLabel idLabel=new JLabel("编号");
    private JLabel nameLabel=new JLabel("名称");
    private JLabel priceLabel=new JLabel("价格");
    private JLabel unitLabel=new JLabel("计价单位");

    protected JTextField  addIdText=new JTextField(6);
    protected JTextField  addNameText=new JTextField(6);
    protected JTextField  addPriceText=new JTextField(6);
    protected JTextField  addUnitText=new JTextField(6);
    private JButton addBtn=new JButton("增加宠物信息");

    protected JTextField  updateIdText=new JTextField(6);
    protected JTextField  updateNameText=new JTextField(6);
    protected JTextField  updatePriceText=new JTextField(6);
    protected JTextField  updateUnitText=new JTextField(6);
    private JButton updateBtn=new JButton("修改宠物信息");

    protected JTextField  delIdText=new JTextField(6);
    private JButton delBtn=new JButton("删除宠物信息");

    public  PetAdminDialog(){
        this(null,true);
    }
    public  PetAdminDialog(Frame  my,boolean modal){
        super(my,modal);
        this.init();
        this.addComponent();
        this.addListener();
    }
    private  void init(){
        this.setTitle("宠物管理");
        this.setSize(600,500);
        MyTools.center(this);
        this.setResizable(false);
    }
    private void addComponent(){
        this.setLayout(null);
        tableLabel.setBounds(265,20,70,25);
        this.add(tableLabel);
        petTable.getTableHeader().setReorderingAllowed(false);//表格列不能移动
        petTable.getTableHeader().setResizingAllowed(false);//不能拖动表格
        petTable.setEnabled(false);//不能更改数据
        tablePane.setBounds(50,50,500,200);
        tablePane.setViewportView(petTable);
        this.add(tablePane);

        idLabel.setBounds(50,250,70,25);
        nameLabel.setBounds(150,250,70,25);
        priceLabel.setBounds(250,250,70,25);
        unitLabel.setBounds(350,250,70,25);
        this.add(idLabel);
        this.add(nameLabel);
        this.add(priceLabel);
        this.add(unitLabel);

        addIdText.setBounds(50,280,80,25);
        addNameText.setBounds(150,280,80,25);
        addPriceText.setBounds(250,280,80,25);
        addUnitText.setBounds(350,280,80,25);
        this.add(addIdText);
        this.add(addNameText);
        this.add(addPriceText);
        this.add(addUnitText);
        addBtn.setBounds(450,280,120,25);
        this.add(addBtn);

        updateIdText.setBounds(50,310,80,25);
        updateNameText.setBounds(150,310,80,25);
        updatePriceText.setBounds(250,310,80,25);
        updateUnitText.setBounds(350,310,80,25);
        this.add(updateIdText);
        this.add(updateNameText);
        this.add(updatePriceText);
        this.add(updateUnitText);
        updateBtn.setBounds(450,310,120,25);
        this.add(updateBtn);

        delIdText.setBounds(50,340,80,25);
        this.add(delIdText);
        delBtn.setBounds(450,340,120,25);
        this.add(delBtn);
    }
    private void addListener(){
        addBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //调用增加宠物信息方法
               addPetItem();
            }
        });
        updateBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //调用修改宠物信息方法
                updatePetItem();
            }
        });
        delBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //调用删除宠物信息方法
               delPetItem();
            }
        });
    }
    //查询抽象方法
    public  abstract void queryPetItem();
    //增加宠物信息抽象方法
    public abstract  void addPetItem();
    //修改宠物信息抽象方法
    public abstract  void updatePetItem();
    //删除宠物信息抽象方法
    public abstract  void delPetItem();
}
